//
//  HomeViewController.m
//  quickDoctor
//
//  Created by zhaowei on 17/3/8.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "HomeViewController.h"
#import "WeatherView.h"


#import "LocationTableController.h"
#import "CycllingView.h"


#import "SJPDepartmentView.h"
#import "CityTableViewController.h"

#import "WeatherController.h"
#import <UIViewController+MMDrawerController.h>
#import <MMDrawerVisualState.h>
#import <MMDrawerController.h>
@interface HomeViewController ()<UIGestureRecognizerDelegate>

@property (nonatomic,strong)UIView *weView;
@property (nonatomic,copy)NSString *locaName;
@property (nonatomic,strong)UIViewController *weatherController;

@property (weak,nonatomic) CycllingView* cycllingView;
@end

@implementation HomeViewController {
    //请求传入地址
    NSString *_name;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}
- (void)setupUI {
    
    //左侧按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"l"] style:UIBarButtonItemStyleDone target:self action:@selector(leftBtn)];
  
    
    //添加手势
    UIPanGestureRecognizer *doubleTap = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
    [doubleTap setMinimumNumberOfTouches:2];
    [self.weatherController.view addGestureRecognizer:doubleTap];
    
    [self.mm_drawerController setDrawerVisualStateBlock:[MMDrawerVisualState swingingDoorVisualStateBlock]];
    
    self.title = @"马医一生";
     self.navigationController.navigationBar.barTintColor = kThemeColor;
    
    //颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor whiteColor];
        //添加weatherViewController
    WeatherController *weaController = [[WeatherController alloc] init];
    _weatherController = weaController;

    self.navigationController.navigationBar.translucent = NO;
    [self.view addSubview:weaController.view];
    //布局
    [weaController.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.leading.trailing.offset(0);
        make.height.mas_equalTo(80);

    }];
    
    weaController.locaName = _locaName;
    _weView = weaController.view;
    self.locaName = _name;
    _weView.backgroundColor = RGBACOLOR(172, 239, 220, 1);
    
    [self addChildViewController:weaController];

    //接收通知
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(clickChose) name:@"push" object:nil];
    
    //添加轮播视图
    [self addCycleView];
    [self setupDepartmentView];
}

#pragma mark
#pragma mark -一个手指双击
- (void)doubleTap:(UITapGestureRecognizer *)gesture {
    
    [self.mm_drawerController bouncePreviewForDrawerSide:MMDrawerSideLeft completion:nil];
}

- (void)leftBtn {
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}

- (void)addCycleView {
    
    CycllingView *cycle = [[CycllingView alloc] init];
    _cycllingView = cycle;
    
    [self.view addSubview:cycle];
    //布局
    [cycle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(80);
        make.leading.trailing.offset(0);
        make.height.mas_equalTo(180);
    }];
}
/// 点击跳转
- (void)clickChose {
    
    //创建tableController
    LocationTableController *locController = [[LocationTableController alloc] init];
    
    [self.navigationController pushViewController:locController animated:YES];
    

    [_weatherController removeFromParentViewController];
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





#pragma
#pragma-添加department控制器

- (void)setupDepartmentView
{
   
    
    CGFloat viewY = self.view.height/2 - 60;
    SJPDepartmentView *departmentView = [[SJPDepartmentView alloc]initWithFrame:CGRectMake(0, viewY, self.view.width, self.view.height/2 )];
    
    [self.view addSubview:departmentView];
    departmentView.backgroundColor = [UIColor lightGrayColor];
    [self addChildViewController:departmentView.childContrller];
   
    
    
}

#pragma mark
#pragma mark -当页面出现的时候打开抽屉模式
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //设置打开抽屉模式
    [self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
}




@end
